<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 300px;
            height: 300px;
            margin: auto;
            /* border: 1px solid #ddd; */
            text-align: center;
            position: relative;
        }
        ul{
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin:30px 88px;
            list-style: none;
            display: none;
        }
        li{
            width: 40px;
            height: 40px;
            line-height: 40px;
            border: 1px solid #ddd;
        }
    </style>
</head>
<body>
    <div class="box">
        <button class="btn">输入法</button>
            <ul>
                <li>简写</li>
                <li>拼音</li>
                <li class="close">关闭</li>
            </ul>
        </div>
</body>
</html>
<script>
     window.onload= function (){
         var s = document.querySelector(".btn")
         var l = document.querySelector("ul")
         var li = document.querySelectorAll("li")
         var c = document.querySelector(".close")
        // 关闭
        c.onclick = function(){
            l.style.display="none"
        }
        // 显示隐藏
        s.onclick = function(){
            if(l.style.display !="block"){
                l.style.display = "block"
            }else{
                c.onclick()
            }
        }
        // 滑过 背景颜色
         for (var i=0;i<li.length;i++){
             li[i].onmouseover = function (){
                 this.style.background = "green"
             }
             li[i].onmouseout  =function(){
                 this.style.background =""
             }
            
         }
     }
</script>